﻿using HalconDotNet;
using Halcon二次开发.Controller.中心距合格检测;
using Halcon二次开发.Controller.数据加载与保存;
using Halcon二次开发.Model.储放所有单例.储存每个单例界面;
using Halcon二次开发.Model.自定义控件;
using Halcon二次开发.View.卡尺;
using Halcon二次开发.View.多模板匹配;
using Halcon二次开发.View.相机;
using Halcon二次开发.View.距离转换工具;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.View.中心距
{
    public partial class DistanceForm : Form
    {
        /// <summary>
        /// 合格检测动作类对象
        /// </summary>
        public SpacedetectionController controller;
        public HwindowFlowNodeUrseControl hwindowFlowNode;
        //当前节点名字
        public string nodeName;
        public DistanceForm(string name, HwindowFlowNodeUrseControl hwindowFlowNode)
        {
            this.hwindowFlowNode = hwindowFlowNode;
            InitializeComponent();
            this.nodeName = name;
            comboBox1.SelectedIndex = 1;
            comboBox3.SelectedIndex = 0;
            controller = new SpacedetectionController(this,hwindowFlowNode);
        }
        /// <summary>
        /// 功能打开与关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 反射调用存储窗体数据
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="nodes"></param>
        public void SetJsonPaths(string filePath, string addres)
        {
            //界面数据保存的路径
            string paths = filePath + "\\" + "界面数据\\" + nodeName + "\\" + addres + "数据.json";
            //调用存储方法
            new LoadData().LoadDatas(paths, this);
        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                //小运行时获取卡尺工具输出的线段
                controller.linesList = (((this.Parent as TabPage).Parent as TabControl).GetControl(0).Tag as PreciseCaliper).controller.linesList;


                foreach (TreeNode item in hwindowFlowNode.treeView1.Nodes)
                {
                     if (item.Name.Contains("相机"))
                    {
                        controller.HideIntputImage = (item.Tag as CamerForm).controller.HideOutputImage;
                    }
                }
                controller.Sum3 = (((this.Parent as TabPage).Parent as TabControl).GetControl(1).Tag as DistanceToolForm).controller.Sum3;
                if (comboBox1.Text.Trim() == "打开")
                {
                    controller.Tool_Run();
                }
            }
            catch (Exception ex)
            {
                (FormDb.Db["Form1"] as Form1).textBox1.AppendText(this.Name + ":" + ex.Message + "\r\n");
            }
        }
    }
}
